<?php
require_once '../inc/configuration.php';
require_once '../inc/connexion_bd.php';

$id = isset($_GET['id']) ? $_GET['id'] : "";

if ($id != "") {
    $where = "WHERE id_entreprise=".$_GET['id'];
} else {
    $where = "";}
    
$order = isset($_GET['ordre']) ? "ORDER BY nom ".$_GET['ordre']." , prenom ".$_GET['ordre'] : "";

$sql = "SELECT * FROM contacts ".$where." ".$order;

$req = mysqli_query($connexion_serveur, $sql); 
        
$nbre_total = mysqli_num_rows($req);        
?>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
            <?php require_once "../inc/css_js_bootstrap/css_js_bootstrap.php"; ?>
    </head>
    <body>
        <?php
        // put your code here        <?php
        require_once '../inc/menus/menu_principal.php';
        ?>
        
        <form>   
            <h2>LISTE DES CONTACTS</h2>
            <h3>Nombre de contacts affichés : <?php  echo $nbre_total; ?></h3>  
        <?php
      
       while($resultats = mysqli_fetch_assoc($req)) {?>
        
            
            
            <table>
                <tr>
                    <td>n°</td>
                    <td><?php echo $resultats["id"]; ?></td>
                </tr>
                 <tr>
                    <td>Nom et prénom</td>
                    <td> <?php echo $resultats["nom"]." ".$resultats["prenom"]; ?></td>
                </tr>
                <tr>
                    <td>Entreprise</td>
                    <td>
                        <?php 
                        //REQUETE SQL
                        $sql_ent = "SELECT raison_sociale FROM entreprises WHERE id=".$resultats["id_entreprise"];
                        $req_ent = mysqli_query($connexion_serveur, $sql_ent);
                        $data_ent = mysqli_fetch_assoc($req_ent);
                        
                        echo $data_ent["raison_sociale"];
                        //echo $resultats["id_entreprise"];
                        ?>
                    </td>
                </tr>
               <tr>
                    <td>Téléphone</td>
                    <td><?php echo $resultats["telephone"]; ?></td>
                </tr>
                <tr>
                    <td>Photo</td>
                    <td><?php echo $resultats["photo"]; ?></td>
                </tr>
                      <tr>
                    <td>Email</td>
                    <td><?php echo $resultats["email"]; ?></td>
                </tr>
                <tr>
                    <td>Observations</td>
                    <td><?php echo $resultats["observations"]; ?></td>
                </tr><br><br>
            </table>
           
            
      <?php 
      
      } ?>
        
        
    </body>
</html>
